package com.example.shuiyin.config;

import com.example.shuiyin.service.MinioStorageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableScheduling
@RequiredArgsConstructor
@Slf4j
public class ScheduleConfig {

    private final MinioStorageService minioStorageService;

    /**
     * 每天凌晨2点自动清理测试文件
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void scheduledCleanupTestFiles() {
        log.info("开始定时清理测试文件...");
        try {
            int deletedCount = minioStorageService.cleanupAllTestFiles();
            log.info("定时清理测试文件完成，共删除{}个文件", deletedCount);
        } catch (Exception e) {
            log.error("定时清理测试文件失败: {}", e.getMessage(), e);
        }
    }
} 